package com.atzqk.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class TestAjaxServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
//
        //判断是否登录成功
        if ("admin".equals(username) && "123456".equals(password)) {
            //响应客户端，处理ajax请求只能使用以下方式响应客户端
            PrintWriter writer = response.getWriter();
            writer.print("yes");
        } else {
            PrintWriter writer = response.getWriter();
            writer.print("no");
        }

//        response.getWriter().print(username+"，"+password);

    }
}
